﻿using Microsoft.Owin.Builder;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;

namespace Jhong.FunMVC.Test
{

    public class Adapter
    {
        static Func<IDictionary<string, object>, Task> _owinAppFunc;

        /// <summary>
        /// 适本器构造函数
        /// </summary>
        public Adapter()
        {
            var builder = new AppBuilder();
            new Startup().Configuration(builder);
            _owinAppFunc = builder.Build();
        }


        /// <summary>
        /// *** JWS或TinyFox所需要的关键函数 ***
        /// <para>每个请求到来，JWS/TinyFox都把请求打包成字典，通过这个函数提供给本应用</para>
        /// </summary>
        /// <param name="env">新请求的环境字典</param>
        /// <returns>返回一个正在运行或已经完成的任务</returns>
        public Task OwinMain(IDictionary<string, object> env)
        {
            return _owinAppFunc != null ? _owinAppFunc(env) : null;
        }



    }

}